import {
    useContext, useEffect
} from "react"
import UserProfileContext from "../context/userProfileContext"
import jsCookie from "js-cookie"
import {
    getUserAccountInfo
} from "../services/user"

export default function useAuth() {
    const userCtx = useContext(UserProfileContext)
    const hasCookie = jsCookie.get("MUSIC_A_T")
    const handleGetUserAccountInfo = () => {
        getUserAccountInfo().then(res => {
            userCtx.setProfile(res.profile);
        })
    }
    useEffect(() => {
        handleGetUserAccountInfo()
    }, [])
    return {
        ...userCtx, hasCookie
    }
}